package com.creditft.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.creditft.common.base.controller.BaseController;
import com.creditft.common.response.Response;
import com.creditft.domain.Book;
import com.creditft.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description:
 * @author: xiaoxiong
 * @create: 2021-03-31 17:29
 */
@RestController
@RequestMapping
public class BookController extends BaseController {

    @Autowired
    private BookService bookService;

    @PostMapping
    public Response<String> save(@RequestBody Book book){
        bookService.save(book);
        return success("success");
    }

    @GetMapping
    public Response<List<Book>> list(){
        return success(bookService.list(Wrappers.<Book>lambdaQuery().orderByAsc(Book::getId)));

    }
    @GetMapping(value = "{id}")
    public Response<Book> book(@PathVariable(value = "id") Integer id){
        return success(bookService.getById(id));

    }
}
